import desmontec.sistema.*
import desmontec.util.Constantes
import java.util.Calendar
import java.util.GregorianCalendar

class BootStrap {
	// lenin.medeiros - INICIO
	def  springSecurityService
	// lenin.medeiros - FIM
	

    def init = { 
		// lenin.medeiros - INICIO
		/* servletContext -> */
		def userRole = SecRole.findByAuthority('ROLE_USER') ?: new SecRole(authority: 'ROLE_USER').save(failOnError: true)
		def adminRole = SecRole.findByAuthority('ROLE_ADMIN') ?: new SecRole(authority: 'ROLE_ADMIN').save(failOnError: true)
		
		Calendar meuCalendario = GregorianCalendar.getInstance()
		Date dataAtual = meuCalendario.getTime()
		
		def adminUser = SecUser.findByUsername('admin') ?: new SecUser(
			username: 'admin',			
			password: springSecurityService.encodePassword('lufeleart'),
			dataValidade: dataAtual,
			nome: 'Adm',
			email: 'adm.gestao.dpg@gmail.com',
			enabled: true).save(failOnError: true)
		new SecUserSecRole(secUser: adminUser, secRole: adminRole).save(flush: true, insert: true)
		// lenin.medeiros - FIM
    }
    def destroy = {
    }
}